import type { PageParams } from '@/types/grobal'
import type {
  OrderCreateParams,
  OrderCreateResult,
  OrderListParams,
  OrderListResult,
  OrderLogisticResult,
  OrderPreResult,
  OrderResult,
} from '@/types/oreder'
import { request } from '@/utils/request'

/**
 * 获取预付订单
 * @returns
 */
export const getOrderPreAPI = () => {
  return request<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre',
  })
}
type OrderPreNowParams = {
  /** 商品skuId */
  skuId: string
  count: string
  addressId?: string
}
/**
 * 获取立即购买订单
 * @param data
 * @returns
 */
export const getOrderPreNowAPI = (data: OrderPreNowParams) => {
  return request<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre/now',
    data,
  })
}
/**
 * 提交订单
 * @param data
 * @returns
 */
export const postOrderAPI = (data: OrderCreateParams) => {
  return request<{ id: string }>({
    method: 'POST',
    url: '/member/order',
    data,
  })
}
/**
 * 获取订单详情
 * @param id 订单id
 * @returns
 */
export const getOrderDetailAPI = (id: string) => {
  return request<OrderResult>({
    method: 'GET',
    url: `/member/order/${id}`,
  })
}
/**
 * 获取再次购买订单
 * @param id
 * @returns
 */
export const getReOrderAPI = (id: string) => {
  return request<OrderPreResult>({
    method: 'GET',
    url: `/member/order/repurchase/${id}`,
  })
}
/**
 * 模拟发货
 * @param id
 * @returns
 */
export const getConsignmentOrderAPi = (id: string) => {
  return request({
    method: 'GET',
    url: `/member/order/consignment/${id}`,
  })
}
/**
 * 确认发货
 * @param id
 * @returns
 */
export const putReceiptOrderAPI = (id: string) => {
  return request<OrderResult>({
    method: 'PUT',
    url: `/member/order/${id}/receipt`,
  })
}
/**
 * 获取订单物流
 * @param id 订单编号
 * @returns
 */
export const getLogisticsOrderAPI = (id: string) => {
  return request<OrderLogisticResult>({
    method: 'GET',
    url: `/member/order/${id}/logistics`,
  })
}
/**
 * 取消订单
 * @param id 订单id
 * @param cancelReason 取消理由
 * @returns
 */
export const putCancelOrderAPI = (id: string, data: { cancelReason: string }) => {
  return request<OrderResult>({
    method: 'PUT',
    url: `/member/order/${id}/cancel`,
    data,
  })
}
/**
 * 删除订单
 * @param data
 * @returns
 */
export const deleteOrderAPI = (data: { ids: string[] }) => {
  return request({
    method: 'DELETE',
    url: '/member/order',
    data,
  })
}
/**
 * 获取订单列表
 * @param data
 * @returns
 */
export const getOrderListAPI = (data: OrderListParams) => {
  return request<OrderListResult>({
    method: 'GET',
    url: '/member/order',
    data,
  })
}
